﻿@model  Model.SysMenuInfo
@{
    ViewBag.Title = "作业任务管理";
    Layout = "~/Views/Shared/_Main.cshtml";
}
<style>
    .panel-tool
    {
        display: none;
    }
    .table_bg td
    {
        white-space: nowrap;
    }
    .trBg
    {
        line-height: 22px;
        background: #efefef;
    }
    .w40
    {
        width: 40px;
    }
    .cw
    {
        width: 33px;
        text-align: center;
        font-weight: bold;
    }
    .c0
    {
        color: #000000;
    }
    .c1
    {
        color: #0000FF;
    }
    .c2
    {
        color: #ff0000;
    }
    .c3
    {
        color: #00FF00;
    }
    .c4
    {
        color: #008000;
    }
</style>
<script type="text/javascript">
    function ButtonSearch() {
        var n = $("#sel_TaskName").val();
        var t = $("#sel_TaskType").val();
        var s = $("#sel_TaskStatus").val();
        $("#DataGrid").treegrid({
            url: "/SysJob/Sreach/?dbName=" + encodeURI($.getUrlParam("dbName")) + "&n=" + encodeURI(n) + "&t=" + encodeURI(t) + "&s=" + encodeURI(s)
        });
    }
    function ViewInfo(id, name) {
        $.post("/SysJob/GetTaskLogItem/?dbName=" + encodeURI($.getUrlParam("dbName")) + "&id=" + id, function (res) {
            jv.SetDivJson($("#LogInfoDialog"), 4, res);
            $("#spa_TaskName").html(name);
        });
        $('#LogInfoDialog').show();
        $('#LogInfoDialog').dialog({
            title: '查看日志信息',
            top: 50,
            buttons: [{
                text: '关闭',
                handler: function () {
                    $('#LogInfoDialog').dialog('close');
                }
            }]
        });
    }
    var timer;
    function View(id, name) {
        $('#ViewDialog').show();
        window.clearInterval(timer)
        $("#ViewGrid").datagrid({
            width: 800,
            height: 320,
            autoRowHeight: false,
            fitColumns: true,
            pagination: true,
            rownumbers: true,
            queryParams: {},
            url: "/SysJob/GetTaskLog/?dbName=" + encodeURI($.getUrlParam("dbName")) + "&id=" + id,
            singleSelect: true,
            striped: true,
            columns: [[
            { field: 'StepName', title: '任务明细', width: 200 },
            { field: 'StartTime', title: '开始时间', width: 130, align: 'center' },
            { field: 'EndTime', title: '结束时间', width: 130, align: 'center' },
            { field: 'RunDuration', title: '持续时间', width: 60, align: 'center' },
            { field: 'BatchTime', title: '执行时间', width: 130, align: 'center' },
            { field: 'TaskStatus', title: '执行状态', width: 60, align: 'center' },
            { field: 'GUID', title: '查看', width: 40, align: 'center', formatter: function (value, rowData, rowIndex) {
                return "<a onclick='ViewInfo(\"" + value + "\",\"" + name + "\");' class='grid_a'>查看</a>";
            }
            }]]
        });
        $('#ViewGrid').datagrid('options').pageNumber = 1;
        $("#ViewGrid").datagrid('reload');
        $('#ViewDialog').dialog({
            title: '查看任务执行日志',
            top: 50,
            dialogClass: "my-dialog",
            buttons: [{
                text: '关闭',
                handler: function () {
                    window.clearInterval(timer);
                    $('#ViewDialog').dialog('close');
                }
            }]
        });
        timer = setInterval("startRequest()", 5000);
    }
    function startRequest() {
        $("#ViewGrid").datagrid('reload');
    }
    function AddItem() {
        window.location.href = "/SysJob/Getjob?dbName=" + encodeURI($.getUrlParam("dbName"));
    }
    function Edit(v) {
        window.location.href = "/SysJob/Getjob/?dbName=" + encodeURI($.getUrlParam("dbName")) + "&id=" + v;
    }
    function DeleteItem(v) {
        if (confirm("确定要删除吗?")) {
            $.post("/SysJob/DeleteItem/?dbName=" + encodeURI($.getUrlParam("dbName")) + "&id=" + v, function (res) {
                if (res == "1") {
                    alert("删除成功!");
                    $("#DataGrid").treegrid('reload');
                } else if (res == "0")
                    alert("删除失败！");
                else
                    alert("删除失败！" + res);
            });

        }
    }
    function DoTask(v) {
        $.post("/SysJob/DoTask/?dbName=" + encodeURI($.getUrlParam("dbName")) + "&id=" + v, function (res) {
            alert(res);
        });
        $("#DataGrid").treegrid('reload');
    }
    function UpStatus(v, s) {
        $.post("/SysJob/UpStatus/?dbName=" + encodeURI($.getUrlParam("dbName")) + "&id=" + v + "&status=" + s);
        $("#DataGrid").treegrid('reload');
    }
    function TaskRunStatus() {
        $('#dl').show();
        $.post("/SysJob/GetTableColumns?dbName=" + encodeURI($.getUrlParam("dbName")), function (result) {
            if (result && result.length > 0) {
                var columnsArray = new Array();
                for (var i = 0; i < result.length; i++) {
                    columnsArray.push({ field: result[i].ColumnName, title: result[i].ColumnDescription, width: 40, align: "center" });
                }
                columnsArray.push({ title: '', width: 40 });
                var dataGridWidth = (result.length * 40);
                $("#TaskRunStatus").datagrid({
                    height: 390,
                    autoRowWidth: true,
                    fitColumns: true,
                    pagination: false,
                    rownumbers: true,
                    striped: true,
                    singleSelect: true,
                    url: '/SysJob/GetTaskRunStatus/?dbName=' + encodeURI($.getUrlParam("dbName")),
                    frozenColumns: [[
	                { title: '任务名称', field: 'TaskName', width: 120 },
	                { title: '任务状态', field: 'TaskStatus', width: 60 },
	                { title: '按日间隔', field: 'TaskIntervalDays', width: 60, align: 'center' },
	                { title: '分钟间隔', field: 'TaskEveryDayIntervalMinute', align: 'center', width: 60 }
				    ]],
                    columns: [columnsArray],
                    onLoadSuccess: function (data) {
                        $(".datagrid-view2 .datagrid-cell").removeAttr("style");
                        $(".datagrid-view2 td").each(function (d) { $(this).find("div").addClass("w40"); });
                    },
                    toolbar: [{
                        id: 'btnSearch',
                        text: '导出到Excel',
                        iconCls: 'icon-search',
                        handler: function () {
                            var arrData = new Array();
                            arrData.push("ExportType=Excel");
                            jv.formNew("/SysJob/ExportData/?dbName=" + encodeURI($.getUrlParam("dbName")), arrData);
                        }
                    }]
                });
            }
        });

        $('#dl').dialog({
            title: '查看任务计划表',
            top: 50,
            dialogClass: "my-dialog",
            buttons: [{
                text: '关闭',
                handler: function () {
                    $('#dl').dialog('close');
                    goto('/SysJob/JobList?dbName=' + encodeURI($.getUrlParam("dbName")));
                }
            }]
        });
    }
    $(function () {
        $('#DataGrid').treegrid({
            title: '作业任务管理',
            height: 480,
            idField: 'TaskID',
            treeField: 'TaskName',
            rownumbers: true,
            animate: true,
            collapsible: false,
            pagination: true,
            url: "/SysJob/Sreach/?dbName=" + encodeURI($.getUrlParam("dbName")) + "&n=&t=&s=",
            striped: true,
            toolbar: [{
                text: '添加',
                iconCls: 'icon-add',
                handler: function () {
                    AddItem();
                }
            }, {
                text: '查看任务计划表',
                iconCls: 'icon-search',
                handler: function () {
                    TaskRunStatus();
                }
            }],
            frozenColumns: [[
	            { title: '任务名称', field: 'TaskName', width: 200 }
				]],
            columns: [[
	        { title: '任务类型', field: 'TaskTypeStr', width: 100, align: 'center' },
	        { title: '执行周期', field: 'TaskIntervalDaysStr', width: 60, align: 'center' },
            { field: 'TaskStartTime', title: '执行时间', width: 120, align: 'center' },
            { field: 'TaskStartDate', title: '生效日期', width: 80, align: 'center' },
            { field: 'TaskEndDate', title: '失效日期', width: 80, align: 'center' },
            { field: 'TaskStatusStr', title: '任务状态', width: 60, align: 'center' },
            { field: 'TaskDescription', title: '操作', width: 245, align: 'center' }
			]]
        });
    });
</script>
<div style="margin: 5px;">
    <table class="table_Search" style="width: 1000px;">
        <tr>
            <td>
                任务名称
                <input id="sel_TaskName" type="text" style="width: 150px;" />
                任务类型
                <select id="sel_TaskType">
                    <option value="">请选择</option>
                    <option value="1">重复执行</option>
                    <option value="0">执行1次后删除</option>
                </select>
                任务状态
                <select id="sel_TaskStatus">
                    <option value="">请选择</option>
                    <option value="0">禁用</option>
                    <option value="1">启用</option>
                    <option value="2">警告</option>
                    <option value="3">成功</option>
                    <option value="4">失败</option>
                </select>
                <input type="button" value=" 搜索 " onclick="ButtonSearch()" />
            </td>
        </tr>
    </table>
    <table id="DataGrid" style="width: 1000px; height: 480px;">
    </table>
</div>
<div id="ViewDialog" style="padding: 5px; width: 840px; height: 420px; display: none;
    word-wrap: break-word; word-break: normal;">
    <table id="ViewGrid">
    </table>
</div>
<div id="LogInfoDialog" style="padding: 5px; width: 500px; height: 330px; display: none;
    word-wrap: break-word; word-break: normal; line-height: 20px;">
    <div style="width: 470px; height: 245px; overflow-y: scroll;">
        <b>任务名称：</b><span id="spa_TaskName"></span><br />
        <b>任务明细：</b><span id="spa_StepName"></span><br />
        <b>开始时间：</b><span id="spa_StartTime"></span><br />
        <b>结束时间：</b><span id="spa_EndTime"></span><br />
        <b>持续时间：</b><span id="spa_RunDuration"></span><br />
        <b>执行时间：</b><span id="spa_BatchTime"></span><br />
        <b>执行结果：</b><span id="spa_Result"></span><br />
        <b>执行状态：</b><span id="spa_TaskStatus"></span><br />
    </div>
</div>
<div id="dl" style="padding: 5px; width: 900px; height: 500px; display: none; word-wrap: break-word;
    word-break: normal; line-height: 20px;">
    <div id="com">
        <span class='c0'>×：不执行</span>。<span class='c1'>√：N分钟间隔并且状态为启用</span>。 <span class='c2'>
            √：N分钟间隔并且状态为禁用</span>。<span class='c3'>√：N天1次并且状态为启用</span>。 <span class='c4'>√：N天1次并且状态为禁用</span></div>
    <table id="TaskRunStatus">
    </table>
</div>
